package com.example.demo.util;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @program: yagena
 * @description:
 * @author: yby
 * @create: 2020-05-30 16:46
 **/
public class PropertyUtil {
    private static final Logger logger = LoggerFactory.getLogger(PropertyUtil.class);
    public static String javaScriptTest(String schemaCode) {
        StringBuffer buffer = new StringBuffer();
        String line = "";
        try {
            File cfgFile = ResourceUtils.getFile("classpath:create.sql");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(cfgFile), "utf-8"));
            while ((line = bufferedReader.readLine()) != null) {
                buffer.append(line);
                buffer.append("\n");
            }
            //System.out.println("buffer="+buffer);
            //替换buffer的内容
        } catch (Exception e) {
            logger.info(e.toString());
        }


        return buffer.toString();
    }

    public static String getConfString(String conf) {
        String result = "";
        ClassLoader classLoader =  PropertyUtil.class.getClassLoader();
        try {
            result = IOUtils.toString(classLoader.getResourceAsStream(conf), "utf-8");
        } catch (IOException e) {
        }
        return result;
    }
    /*public static String replaceSpace(StringBuffer str) {
        if(str==null)
            return null;
        StringBuffer newstr=new StringBuffer();
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)==' '){
                newstr.append('%');
                newstr.append('2');
                newstr.append('0');
            }else{
                newstr.append(str.charAt(i));
            }

        }
        return newstr.toString();
    }*/


    public static void main(String[] args) {
/*        String str = javaScriptTest("cc");
        String s = str.replaceAll("ship001", "ship009");
        System.out.println("str="+s);
        String str1 = "1111aaaa";
        System.out.println(str1.replaceAll("1","b"));*/
        System.out.println( getConfString("create.sql"));

    }

}
